package com.example.oms.service.impl;

import com.example.oms.common.enums.DeliveryCodeStatus;
import com.example.oms.common.enums.SmsStatus;
import com.example.oms.dto.entity.OmsOrderEntity;
import com.example.oms.dto.entity.OmsSmsTaskEntity;
import com.example.oms.dto.ro.SmsCallBackRO;
import com.example.oms.mapper.OmsOrderMapper;
import com.example.oms.mapper.OmsSmsTaskMapper;
import com.example.oms.service.SmsStepService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class FinishStepServiceImpl extends SmsStepServiceImpl implements SmsStepService {

    @Resource
    private OmsSmsTaskMapper omsSmsTaskMapper;

    @Resource
    private OmsOrderMapper omsOrderMapper;

    /**
     * todo 暂时更改task状态和修改提货码状态,后续决定是否在这里继续订单操作
     *
     * @param ro 回调参数
     */
    @Transactional
    @Override
    public void handleSmsStatus(SmsCallBackRO ro) {
        super.handleSmsStatus(ro);
        OmsSmsTaskEntity omsSmsTaskEntity = omsSmsTaskMapper.selectById(ro.getSendId());
        OmsOrderEntity omsOrderEntity = omsOrderMapper.selectById(omsSmsTaskEntity.getOmsOrderId());
        omsOrderEntity.setDeliveryCodeStatus(DeliveryCodeStatus.HAVE_BEEN_USED.getValue());
        omsOrderEntity.setUpdateBy("");
        omsOrderEntity.setUpdateTime(new Date());
        omsOrderMapper.updateById(omsOrderEntity);
    }
}
